package utilites;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class ViewUtilites {
	
	public static java.sql.Date convert (String temp)
	{
		SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy");
		
		java.util.Date date = null;
		
		try {
			
			date = sdf.parse(temp);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		java.sql.Date dates = new java.sql.Date(date.getTime());
		return dates;
	}
	
	public static void setList(JList list, String[] data)
	{
		DefaultListModel dl=(DefaultListModel) list.getModel();
		for(int i=0;i<data.length;i++)
		{
			dl.addElement(data[i]);
		}
	}
	
	
	public static String[][] ret_data(JTable tab)
	{		DefaultTableModel dm=(DefaultTableModel) tab.getModel();
	        int rowcount=dm.getRowCount();
	        int colcount=dm.getColumnCount();
	        String[][] rd=new String[rowcount][colcount];
	        for(int i=0;i<rowcount;i++)	        	
	        {
	        	for(int j=0;j<colcount;j++)
	        	{
	        		rd[i][j]= dm.getValueAt(i,j)+"";
	        	}
	        }
		return rd;
	}
	
	


public boolean   date_val(String temp)
{

	java.util.Date date = null;
	SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy");
	
	try {
		
		date = sdf.parse(temp);
	} catch (ParseException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return false;
	}
	return true;
}

public static void set_comboBox(JComboBox com,String[]items)
{
	int itemCount = com.getItemCount();

    for(int i=itemCount-1;i>-1;i--){
        com.removeItemAt(i);
     }
		for(int i=0;i<items.length;i++)
		{
			com.addItem(items[i]);
		}
}


public static void refreshTable(JTable temp)
{
	DefaultTableModel dtm=(DefaultTableModel) temp.getModel();
	
	int rCount=dtm.getRowCount();
	
	for(int i=rCount-1;i>=0;i--)
	{
		dtm.removeRow(i);
	}
}

public static void setAutoSuggestionsComboBox(JComboBox x)
{
	AutoCompleteJComboBoxer auto=new AutoCompleteJComboBoxer(x);
}


}
